﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace RemedyMVC
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            //routes.IgnoreRoute("api/{*pathInfo}");

            routes.MapRoute(
               null,
               "Tree/Query/{form}/{Top}",
               new { controller = "Tree", action = "Query" } // Parameter defaults
               );

            ///Menu/Query/NRemedy.WS_IncidentStatus/100000/100001/0
            routes.MapRoute(
                null,
                "Table/Query/{form}",
                new { controller = "Table", action = "Query" } // Parameter defaults
                );

            ///Menu/Query/NRemedy.WS_IncidentStatus/100000/100001/0
            routes.MapRoute(
                null,
                "Menu/Query/{form}/{vid}/{tid}",
                new { controller = "Menu", action = "Query" } // Parameter defaults
                );

            routes.MapRoute("simple", "Journal/Form/{type}/{formmodel}/{id}",
                new
                {
                    controller = "Journal",
                    action = "Form",
                    id = UrlParameter.Optional
                });

            routes.MapRoute(
              null, // Route name
              string.Format("{{controller}}/{{action}}/{{{0}}}/{{id}}", NRemedy.MVC.UI.NRemedyUIExtension.FormModelKey), // URL with parameters
              new { controller = "Account", action = "Index" } // Parameter defaults
          );

            routes.MapRoute(
                null, // Route name
                string.Format("{{controller}}/{{action}}/{{{0}}}", NRemedy.MVC.UI.NRemedyUIExtension.FormModelKey), // URL with parameters
                new { controller = "Account", action = "Index" } // Parameter defaults
            );



            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Account", action = "Login", id = UrlParameter.Optional } // Parameter defaults
            );



        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}